
package cn.com.pusai.common.service.impl;

import cn.com.pusai.common.dao.BaseDAO;
import cn.com.pusai.common.service.BaseService;
import cn.com.pusai.common.util.SearchMap;
import cn.com.pusai.core.exception.ServiceException;
import cn.com.pusai.core.page.DefaultPageResult;
import cn.com.pusai.core.page.PageResult;
import java.io.Serializable;
import java.util.List;
import org.apache.log4j.Logger;

public class BaseServiceImpl
	implements BaseService
{

	public Logger logger;
	private BaseDAO DAO;

	public BaseServiceImpl()
	{
		logger = Logger.getLogger(getClass());
	}

	public BaseDAO getDAO()
	{
		return DAO;
		
	}

	public void setDAO(BaseDAO dao)
	{
		DAO = dao;
	}

	public Object findObjectById(Serializable id)
	{
		return DAO.findObjectById(id);
	}

	public Object findObjectById(Serializable id, Class objectClass)
		
	{
		return DAO.findObjectById(id, objectClass);
	}

	public void delete(Object object)
		
	{
		DAO.delete(object);
	}

	public void delete(Serializable id)
		
	{
		DAO.delete(id);
	}

	public void delete(Serializable id, Class objectClass)
		
	{
		DAO.delete(id, objectClass);
	}

	public void delete(Serializable ids[])

	{
		DAO.delete(ids);
	}

	public void delete(Serializable ids[], Class objectClass)
	
	{
		DAO.delete(ids, objectClass);
	}

	public void update(Object object)

	{
		DAO.update(object);
	}

	public void updateObjectProperty(Serializable id, String propertyName, Object propertyValue, Class objectClass)

	{
		DAO.updateObjectProperty(id, propertyName, propertyValue, objectClass);
	}

	public void updateObjectProperty(Serializable ids[], String propertyName, Object propertyValue, Class objectClass)
	
	{
		DAO.updateObjectProperty(ids, propertyName, propertyValue, objectClass);
	}

	public void updateObjectProperty(Serializable id, String propertyNames[], Object propertyValues[], Class objectClass)
		
	{
		DAO.updateObjectProperty(id, propertyNames, propertyValues, objectClass);
	}

	public void updateObjectProperty(Serializable ids[], String propertyNames[], Object propertyValues[], Class objectClass)
	
	{
		DAO.updateObjectProperty(ids, propertyNames, propertyValues, objectClass);
	}

	public void create(Object object)
	
	{
		DAO.create(object);
	}

	public List findObjects(SearchMap searchMap)
		throws ServiceException
	{
		return DAO.findObjects(searchMap);
	}

	public List findObjects(SearchMap searchMap, Class objectClass)
		throws ServiceException
	{
		return DAO.findObjects(searchMap, objectClass);
	}

	public PageResult findObjectsForPage(int pageNo, int maxPageSize, SearchMap searchMap)
		throws ServiceException
	{
		long totalCount = DAO.getCount(searchMap);
		List list = DAO.findObjects(DefaultPageResult.adjustPageNo(totalCount, pageNo, maxPageSize), maxPageSize, searchMap);
		return new DefaultPageResult(list, totalCount, DefaultPageResult.pageNoToStartIndex(totalCount, pageNo, maxPageSize), maxPageSize);
	}

	public PageResult findObjectsForPage(int pageNo, int maxPageSize, SearchMap searchMap, Class objectClass)
		throws ServiceException
	{
		long totalCount = DAO.getCount(searchMap, objectClass);
		List list = DAO.findObjects(DefaultPageResult.adjustPageNo(totalCount, pageNo, maxPageSize), maxPageSize, searchMap, objectClass);
		return new DefaultPageResult(list, totalCount, DefaultPageResult.pageNoToStartIndex(totalCount, pageNo, maxPageSize), maxPageSize);
	}

	public boolean isExist(Serializable id, String propertyName, String propertyValue, Class objectClass)
		throws ServiceException
	{
		return DAO.isExist(id, propertyName, propertyValue, objectClass);
	}

	public boolean isExistAnd(Serializable id, String propertyNames[], String propertyValues[], Class objectClass)
		throws ServiceException
	{
		if (propertyNames.length != propertyValues.length)
			throw new RuntimeException("propertyNames和propertyValues数组的长度不相等");
		else
			return DAO.isExistAnd(id, propertyNames, propertyValues, objectClass);
	}

	public List isExistOr(Serializable id, String propertyNames[], String propertyValues[], Class objectClass)
		throws ServiceException
	{
		throw new RuntimeException("暂不支持isExistOr");
	}
}
